43

Explore Your Deductive Logic—Sudoku

43

STEP 6 continued

    For j =​ 1 To 9

      notahome =​ 0

      If sbox(i, j) <> ““ Then notahome =​ 1

      For k =​ 1 To 9

        If cantbelist(i, j, k) =​ putnumber Then notahome =​ 1

      Next k

      If notahome =​ 1 Then

        notahomecount =​ notahomecount +​ 1

      Else

        home =​ j

      End If

    Next j

    If notahomecount =​ 8 Then

      sbox(i, home) =​ putnumber

      Remember to update cantbelist since we uncovered a new empty cell!

      Call updatecantbelist(putnumber, i, home)

      Cells(i, home) =​ sbox(i, home)

    End If

End If

Next i

:

:

Next putnumber

STEP 7

Now check all rows column by column for all numbers 1–​9 (putnumber)

if the number is invalid in eight of the nine cells in the same row, then the number

must belong to the ninth cell (empty, of course).

For putnumber =​ 1 to 9

:

:

For j =​ 1 To 9

    numberfound =​ 0

    For i =​ 1 To 9

      If sbox(i, j) =​ putnumber Then numberfound =​ 1

    Next i

If numberfound =​ 0 Then

    notahomecount =​ 0

    For i =​ 1 To 9

      notahome =​ 0

      If sbox(i, j) <> ““ Then notahome =​ 1

      For k =​ 1 To 9

        If cantbelist(i, j, k) =​ putnumber Then notahome =​ 1

      Next k

      If notahome =​ 1 Then

        notahomecount =​ notahomecount +​ 1